a = ['Rose', 'Mike', 'John']

# 元素替换
a[0] = 'Alex'
print(a)
# ['Alex', 'Mike', 'John']

# 删除 item
del a[1]
print(a)
# ['Alex', 'John']

# 分片赋值
b = ['a', 'b', 'c']
b[1:] = ['1', '2', '3']
print(b)
# ['a', '1', '2', '3']

# append: 在后面插入一个元素
c = [1,2,3]
c.append(4)
print(c)
# [1, 2, 3, 4]

# clear: 清空列表
print(c.clear())
# none

# copy: 复制列表
d = [2,3,4]
e = d.copy()
print(e)
# [2, 3, 4]

# count: 某元素出现的次数
f = [1,1,2,2,2,2,3]
print(f.count(1))
# 2
print(f.count(2))
# 4
print(f.count(3))
# 1

# extend: 在尾部扩展
aa = [1,2,4]
aa.extend([0,0,0])
print(aa)
# [1, 2, 4, 0, 0, 0]

# index: 查找某元素第一次出现的位置
bb = [1,2,3]
print(bb.index(1))
# 0
# print(bb.index(0))
# 报错

# insert: 将元素插入到指定索引的位置
cc = [1,2,4]
cc.insert(2,[0,0,0])
print(cc)
# [1, 2, [0, 0, 0], 4]

# pop: 删除某一个项(默认是最后一个), 并返回被删除的值
dd = [1,2,3,4,5]
ee = dd.pop()
print(dd)
# [1, 2, 3, 4]
print(ee)
# 5

# remove: 由于移除某个值的第一次匹配的项
ee = [1,2,2,2,3]
ee.remove(2)
print(ee)
# [1, 2, 2, 3]

# reverse: 反转
dd = [0, 1, 2, 3, 4]
dd.reverse()
print(dd)
# [4, 3, 2, 1, 0]

# sort: 排序
ee = [0,3,1,5,8]
ee.sort()
print(ee)
# [0, 1, 3, 5, 8]
ee.reverse()
print(ee)
# [8, 5, 3, 1, 0]

ff = ['a', 'b', 'A', 'B', 'c']
ff.sort()
print(ff)
# ['A', 'B', 'a', 'b', 'c']
ff.reverse()
print(ff)
# ['c', 'b', 'a', 'B', 'A']

name = ['Mike', 'John', 'Alex']
name.sort()
print(name)
# ['Alex', 'John', 'Mike']